VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Private Declare Function GetPrivateProfileString _
                Lib "kernel32" _
                Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String _
                                                , ByVal lpKeyName As Any _
                                                , ByVal lpDefault As String _
                                                , ByVal lpReturnedString As String _
                                                , ByVal nSize As Long _
                                                , ByVal lpFileName As String) As Long
                                                
                                                
                                                
Private Declare Function WritePrivateProfileString _
                Lib "kernel32" _
                Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String _
                                                  , ByVal lpKeyName As Any _
                                                  , ByVal lpString As Any _
                                                  , ByVal lpFileName As String) As Long

'/*--------------------------------------------------------------------------------
'                                                          11/31/2013 code by Devin

'                                                      read key value from ini-file
'
'--------------------------------------------------------------------------------*/


Public Function readFromINI(ByVal readSection As String, _
                            ByVal readKey As String, _
                            Optional ByVal iniFile As String = "" _
                            ) As String
    Dim readBuffer As String
    Dim bufferSize As Long
    
    On Error GoTo handleErr
    readBuffer = Space$(255)
    bufferSize = Len(readBuffer)
    If iniFile = "" Then iniFile = MODULE_PATH + "Server.ini"
    
    bufferSize = GetPrivateProfileString(readSection _
                                       , readKey _
                                       , "" _
                                       , readBuffer _
                                       , bufferSize _
                                       , iniFile)

    If bufferSize > 0 Then
        readFromINI = Left$(readBuffer, bufferSize)
    Else
        readFromINI = ""
    End If
    Exit Function
    
handleErr:
    Call showErr("Common.CFile", "readFromINI", Err.Description)

End Function

'/*--------------------------------------------------------------------------------
'                                                          11/05/2013 Code by Devin
'
'    The difference between readFromINI function and readFromINIEX function is that
'
'   readFromINI get key value by function name while readFromINIEX get key value by
'
'   its parameters of keyValue
'
'--------------------------------------------------------------------------------*/

Public Function readFromINIEx(ByVal readSection As String, _
                              ByVal readKey As String, _
                              ByRef keyValue As String, _
                              Optional ByVal iniFile As String = "" _
                              ) As Boolean
    Dim readBuffer As String
    Dim bufferSize As Long
    
    On Error GoTo handleErr
    readFromINIEx = False
    readBuffer = Space$(255)
    keyValue = ""
    If iniFile = "" Then iniFile = MODULE_PATH + "Server.ini"
    bufferSize = Len(readBuffer)
    bufferSize = GetPrivateProfileString(readSection _
                                       , readKey _
                                       , "" _
                                       , readBuffer _
                                       , bufferSize _
                                       , iniFile)
                                       
    If bufferSize > 0 Then
        keyValue = Left$(readBuffer, bufferSize)
        readFromINIEx = True
    Else
        keyValue = ""
    End If
    Exit Function
    
handleErr:
Call showErr("Common.CFile", "readFromINIEx", Err.Description)
    
End Function


'/*--------------------------------------------------------------------------------
'                                                          11/05/2013 Code by Devin
'
'                                                       Write a value into ini-file
'
'--------------------------------------------------------------------------------*/

Public Sub writeToINI(ByVal writeSection As String, _
                      ByVal writeKey As String, _
                      ByVal writeValue As String, _
                      Optional ByVal iniFile As String = "" _
                      )
    On Error GoTo handleErr
    If iniFile = "" Then iniFile = MODULE_PATH + "Server.ini"
    
    Call WritePrivateProfileString(writeSection _
                                 , writeKey _
                                 , writeValue _
                                 , iniFile)
    Exit Sub
    
handleErr:
    Call showErr("Common.CFile", "writeToINI", Err.Description)
End Sub

'/*--------------------------------------------------------------------------------
 '                                                         12/16/2013 Code by Jelly
 '
 '          read a line of characters from text file specified by lineNum parameter
 '
 '-------------------------------------------------------------------------------*/
Public Function readLineString(ByVal fileName As String _
                             , ByVal lineNum As Long) As String
    Dim i As Long
    Dim lineString As String
    i = 1
    Open fileName For Input As #1
    Do While Not EOF(1)
        Line Input #1, lineString
        
        If i = lineNum Then
            readLineString = lineString
            Exit Do
        End If
        i = i + 1
    Loop
    readLineString = ""
    Close #1
End Function
                              

